<template>
  <div class="group-store">
    <div class="table-title">
      <el-select v-model="searchData.policyType" placeholder="请选择政策">
        <el-option v-for="m in PolicyConfigList" :label="m.Name" :value="m.Code" :key="m.Code"></el-option>
      </el-select>
			<el-date-picker
        v-model="dateTime"
        type="daterange"
        :editable="false"
        :clearable="false"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
          @change="getDate">
      </el-date-picker>
			<el-button type="primary" data-auth="bloc_order_view" @click="initList">查询</el-button>
    </div>
    <div class="table-content">
      <div class="" v-for="(m,index) in tableData" style="margin-bottom:20px;">
        <div class="group-title" @click="showTable(index)">
          <i v-show="!m.isopen" class="el-icon-arrow-down"></i>
          <i v-show="m.isopen" class="el-icon-arrow-up"></i>
          <span>酒店名称：{{m.HotelName}}</span>
          <span>可预订总数：{{m.HotelRoomCount}}</span>
        </div>
        <el-table
          v-show="m.isopen"
          :key="m.HotelId"
          border
          :data="m.DetailList"
          :span-method="(value) => objectSpanMethod(value, m.DetailList.length)"
          style="width: 100%">
          <el-table-column
            label="房型"
            prop="CategoryName">
          </el-table-column>
          <el-table-column
            label="可预订房间数"
            prop="RoomCount">
          </el-table-column>
          <el-table-column
            label="政策名称"
  					prop="PolicyConfigName">
          </el-table-column>
          <el-table-column
            label="价格"
            prop="AvgPrice">
          </el-table-column>
          <el-table-column
            label="预订数量">
            <template slot-scope="scope">
               <el-input-number v-model="scope.row.RoomList" @change="val=>{handleChange(val,scope.row,m.DetailList,m)}" :min="0" :max="scope.row.RoomCount"></el-input-number>
            </template>
          </el-table-column>
          <el-table-column label="操作" style="text-align:center">
            <template slot-scope="scope">
  						<el-button
                type="warning" round
                @click="handleAdd(scope.$index, m)">预定</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

        <el-dialog
          :title="dialogTitle"
          :visible.sync="roomShow"
          :close-on-click-modal="false"
          :close-on-press-escape="false"
          @close="initList"
          width="990px"
          center>
          <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px">
            <div class="user-title">客户信息</div>
            <div class="user-info">
              <el-form-item label="联系人：" size="mini" prop="ContactName">
                <el-autocomplete
                  v-model="ruleForm.ContactName"
                  :fetch-suggestions="querySearchAsync"
                  placeholder="请输入内容"
                  @select="val=>{ruleForm.ContactPhone=val.Phone}"
                ></el-autocomplete>
              </el-form-item>
              <el-form-item label="手机号：" size="mini" prop="ContactPhone">
                <el-input :maxlength="11" v-model="ruleForm.ContactPhone"></el-input>
              </el-form-item>
              <el-form-item label="来源渠道：" size="mini" label-width="95px" prop="FromChannel">
                <el-select v-model="ruleForm.FromChannel" placeholder="请选择" @change="getFromChannel1(ruleForm.FromChannel)">
                  <el-option
                    v-for="m in ChannelList"
                    :label="m.Name"
                    :value="parseInt(m.Code)"
                    :key="m.Code">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="渠道商：" size="mini" label-width="80px" prop="TravelAgency" v-if="ruleForm.FromChannel==7||ruleForm.FromChannel==8">
                <el-select v-model="ruleForm.TravelAgency" filterable placeholder="请选择">
                  <el-option
                    v-for="m in ChannelChildList"
                    :label="m.Name"
                    :value="parseInt(m.Code)"
                    :key="m.Code">
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="销售员：" size="mini" label-width="80px" prop="SalesmanId">
                  <el-select v-model="ruleForm.SalesmanId" placeholder="请选择" filterable>
                    <el-option
                      label="无"
                      :value="0">
                    </el-option>
                    <el-option
                      v-for="m in SalesmanList"
                      :label="m.JobNo+'-'+m.Name"
                      :value="m.Id"
                      :key="m.Id">
                    </el-option>
                  </el-select>
              </el-form-item>
              <el-form-item label="支付类型：" size="mini" label-width="95px" prop="PaymentMode">
                  <el-select v-model="ruleForm.PaymentMode" placeholder="请选择">
                    <el-option :label="'全额预付'" :value="1"></el-option>
    								<el-option :label="'部分预付'" :value="2"></el-option>
    								<el-option :label="'到店现付'" :value="3"></el-option>
    								<el-option :label="'已担保（未支付）'" :value="4"></el-option>
                  </el-select>
              </el-form-item>
            </div>
            <div class="room-form">
              <div class="room-row">

              </div>
              <div class="room-row" v-for="(m,index) in dialogData">
                <el-form-item label="入住：" size="mini" label-width="60px" prop="startDate" class="date-form sdate" style="width:33%">
                  {{m.startDate}}
                </el-form-item>
                <el-form-item label="离店：" size="mini" label-width="60px" prop="endDate" class="date-form edate" style="width:33%">
                  {{m.endDate}}
                </el-form-item>
                <el-form-item label="共" label-width="15px" style="width:33%">
                  {{getAlldate(m.startDate,m.endDate).length===1?1:getAlldate(m.startDate,m.endDate).length-1}}晚
                </el-form-item>
                <br/>
                <el-form-item label="房间：" label-width="60px" prop="roomId" style="width:200px">
                  <el-select v-model="m.roomId" size="mini" placeholder="请选择" disabled @change="getMroomData(m,index)">
                    <el-option
                      v-for="n in roomNumData"
                      :key="n.roomId"
                      :label="n.roomName"
                      :value="n.roomId">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="政策：" label-width="60px" prop="roomId" style="width:200px">
                  <el-select v-model="m.PolicyId" size="mini" placeholder="请选择" disabled @change="getroomPrice(m)">
                    <el-option v-for="n in m.CategoryList" :label="n.PolicyName" :value="n.PolicyConfigId" :key="n.Id"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="房间数：" label-width="80px" prop="RoomCount" style="width:250px">
                  <el-input-number v-model="m.RoomCount" :min="1" @change="val=>{roomChange(val,m,dialogData,m)}" :max="m.AllRoom"></el-input-number>
                </el-form-item>
                 <el-form-item label="价格：" label-width="60px" size="mini" prop="AllAmount">
                   <el-input v-model="m.AllAmount" @change="getAllAmount"></el-input>
                 </el-form-item>
              </div>
            </div>
            <div style="padding-right:20px;margin: 10px;">
              <el-dropdown trigger="hover" placement="top" @command="addPriceInfo">
                <span class="el-dropdown-link" style="cursor:pointer;color: #399be6;margin-left:10px;">添加款项</span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item :command="{type:1,name:'收款'}">收款</el-dropdown-item>
                  <el-dropdown-item :command="{type:2,name:'商品'}">商品</el-dropdown-item>
                  <el-dropdown-item :command="{type:3,name:'收押金'}">收押金</el-dropdown-item>
                  <el-dropdown-item :command="{type:4,name:'退款'}">退款</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
            <el-table
              :data="tableDatas"
              style="width: 95%;margin:5px auto 15px;max-height: 200px;overflow: auto;"
              v-show="true">
              <el-table-column
                prop="CashierItem"
                label="项目">
                <template slot-scope="scope">
                  {{CashierItem[scope.row.CashierItem]}}
                </template>
              </el-table-column>
              </el-table-column>
              <el-table-column
                prop="Amount"
                label="收款">
              </el-table-column>
              <el-table-column
                label="支付方式">
                <template slot-scope="scope">
                  {{getCash(scope.row.CashierChannel)}}
                </template>
              </el-table-column>
              <el-table-column
                prop="Remark"
                label="财务备注">
                <template slot-scope="scope">
                  {{scope.row.Remark||''}}
                </template>
              </el-table-column>
              <el-table-column
                label="操作"
                class="delete-td">
                <template slot-scope="scope">
                  <span @click="tableDatas.splice(scope.index,1)" style="color:rgb(57, 155, 230);cursor:pointer;">删除</span>
                </template>
              </el-table-column>
            </el-table>
            <div class="user-title remark-div">
              <el-form-item label="备注：" label-width="60px" prop="Remark">
                <el-input type="textarea" v-model="ruleForm.Remark"></el-input>
              </el-form-item>
            </div>
            <div class="price-div">
              <span>订单总金额：{{ruleForm.AllAmount}} 元</span>
            </div>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitOrder">{{OrderAction===2?'直接入住':OrderAction===0?'确认修改':'预定'}}</el-button>
            <el-button @click="initList">取 消</el-button>
          </span>
        </el-dialog>
        <el-dialog
          :title="priceTitle"
          :visible.sync="priceShow"
          width="350px"
          center>
          <el-form :model="priceForm" :rules="pricerules" ref="priceForm" label-width="100px">
            <el-form-item label="金额：" prop="Amount">
              <el-input v-model="priceForm.Amount" ref="priceFormAmount"></el-input>
            </el-form-item>
            <el-form-item label="支付方式：" prop="CashierChannel">
              <el-select v-model="priceForm.CashierChannel" placeholder="请选择">
                <el-option
                  v-for="m in CashierChannelList"
                  :label="m.Name"
                  :value="parseInt(m.Code)"
                  :key="m.Code">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="财务备注：" prop="Remark">
              <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" v-model="priceForm.Remark"></el-input>
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button v-if="!roomShow" type="primary" @click="addPriceBtn('priceForm')">保存</el-button>
            <el-button v-else type="primary" @click="addPriceRoomIn('priceForm')">保存</el-button>
            <el-button @click="priceShow = false">取 消</el-button>
          </span>
        </el-dialog>

  </div>
</template>
<script>
  export default {
    data () {
      return {
        CashierChannelList:[],
        priceShow:false,
        priceTitle:'',
        priceForm:{
          Amount:'',
          Remark:'',
          CashierChannel:'',
        },
        pricerules:{
          Amount: [
            { required: true, message: '请输入金额', trigger: 'blur' },
          ],
          Remark: [
            { required: false, message: '', trigger: 'blur' },
          ],
          CashierChannel: [
            { required: true, message: '请选择支付方式', trigger: 'change' },
          ],
        },
        pageTotal:0,
        searchData:{
					StartDate:'',
          EndDate:'',
          policyType:''
        },
        OrderAction:1,
				dateTime:[],
        tableData:[],
        tableDatas:[],
        selectedRoom:[],
        PolicyConfigList:[],
        SalesmanList:[],
        ChannelList:[],
        ChannelChildList:[],
        CashierItem:{1:'房费',2:'商品',3:'押金',4:'退款'},
				infoShow:false,
				userInfoData:{},
				dialogTitle:'',
        dialogData:[],
        roomNumData:[],
				roomShow:false,
        ruleForm: {
          ContactName: '',
          ContactPhone: '',
          FromChannel: '',
          SalesmanName: '',
          Remark:'',
          AllAmount:'',
          SellingPriceAmount:'',
          PaymentMode:'',
          SalesmanId:0,
          TravelAgency:''
        },
        rules: {
          ContactName: [
            { required: true, message: '请输入联系人', trigger: 'blur' },
          ],
          ContactPhone: [],
          FromChannel: [
            { required: true, message: '请选择来源渠道', trigger: 'change' },
          ],
          TravelAgency: [
            { required: true, message: '请选择渠道商', trigger: 'change' },
          ],
          SalesmanId: [],
          PaymentMode: [
            { required: true,type:'number',message: '请选择支付类型', trigger: 'change' },
          ]
        },
      }
    },
    created(){
			this.dateTime=[new Date(),new Date(new Date().getTime() + 3600 * 1000 * 24)];
      this.$ajax.getpricepolicytypes().then(res=>{
        if(res.Success&&res.Data){
          this.PolicyConfigList=res.Data;
          this.searchData.policyType=this.PolicyConfigList[0].Code;
          this.getDate(this.dateTime);
        }
      })
      this.$ajax.PayTypes().then(res=>{
        if(res.Success){
          this.CashierChannelList=res.Data;
        }
      })
    },
    methods:{
      getCash(id){
        let name='';
        this.CashierChannelList.forEach(val=>{
          if(val.Code==id){
            name=val.Name
          }
        })
        return name
      },
      showTable(m){
        let data=_.cloneDeep(this.tableData[m])
        data.isopen=!data.isopen;
        this.$set(this.tableData,m,data);
      },
      objectSpanMethod({ row, column, rowIndex, columnIndex },rowspan) {
        if (columnIndex === 5) {
          if (rowIndex % 2 === 0) {
            return {
              rowspan:rowspan,
              colspan: 1
            };
          } else {
            return {
              rowspan: 0,
              colspan: 0
            };
          }
        }
      },
      handleChange(val,data,m,allData){
        let num=0;
        _.map(m,value=>{
          if(data.CategoryId===value.CategoryId){
            num+=(!value.RoomList?0:value.RoomList)
          }
        })
        if(num>data.RoomCount){
          this.$nextTick(()=>{
            data.RoomList=val-1;
          })
        }
        this.$nextTick(()=>{
          if(this.selectedRoom.some(value=>{return value.PolicyDetailId==data.PolicyDetailId})){
            _.map(this.selectedRoom,(value,i)=>{
              if(value.PolicyDetailId==data.PolicyDetailId){
                value.RoomCount=val;
              }
            })
          }else{
            this.selectedRoom.push({
              HotelId:allData.HotelId,
              date:this.searchData.StartDate,
              roomId:data.CategoryId,
              roomName:data.CategoryName,
              PolicyName:data.PolicyConfigName,
              PolicyId:data.PolicyConfigId,
              Id:data.CategoryId,
              Price:data.AvgPrice,
              PolicyDetailId:data.PolicyDetailId,
              RoomCount:val,
              AllRoom:data.RoomCount,
              PolicyPriceAmount:data.AvgPrice
            });
          }
          if(data.RoomList===0){
            _.map(this.selectedRoom,(value,i)=>{
              if(value.PolicyDetailId==data.PolicyDetailId){
                this.selectedRoom.splice(i,1);
              }
            })
          }
        })
      },
      roomChange(val,data,m){
        let num=0;
        _.map(m,value=>{
          console.log(value)
          if(data.roomId===value.roomId){
            num+=(!value.RoomCount?0:value.RoomCount)
          }
        })
        if(num>data.AllRoom){
          this.$nextTick(()=>{
            data.RoomCount=val-1;
          })
        }
        this.getroomPrice(data);
      },
			getDate(date){
        if(this.searchData.StartDate===this.$format('yyyy-MM-dd',new Date(date[0])) && this.searchData.EndDate===this.$format('yyyy-MM-dd',new Date(date[1])))return;
        this.searchData.StartDate=this.$format('yyyy-MM-dd',new Date(date[0]))
        this.searchData.EndDate=this.$format('yyyy-MM-dd',new Date(date[1]))
        this.initList();
      },
      initList(){
        this.roomShow=false;
				this.infoShow=false;
        this.selectedRoom=[];
        this.getList();
      },
      changePage(size){
        this.getList();
      },
      getList(){
        this.$ajax.BlocReserveQuery(this.searchData).then(res=>{
          if(res.Success){
            let data=_.cloneDeep(this.tableData);
            this.tableData=res.Data;
            _.map(this.tableData,(val,index)=>{
              _.map(data,value=>{
                if(value.HotelId===val.HotelId){
                  val.isopen=value.isopen||false
                }
              })
            })
          }else{
            this.tableData=[];
          }
        },rej=>{
          this.tableData=[];
        })
      },
      GetConfigList(){
        this.$ajax.getpricepolicytypes().then(res=>{
          if(res.Success&&res.Data){
            this.PolicyConfigList=res.Data;
            this.searchData.policyType=this.PolicyConfigList[0].Code;
          }
        })
      },
      getAlldate(start,end){
        let bd = new Date(start),be = new Date(end);
        let bdTime = bd.getTime(), beTime = be.getTime(),timeDiff = beTime - bdTime;
        let dArr = [];
        for(var i=0; i<= timeDiff; i+=86400000){
          var ds = this.$format('yyyy-MM-dd',new Date(bdTime+i));
          dArr.push(ds)
        }
        return dArr
      },
      resetForm(formName) {
        if(!this.$refs[formName]){return};
        this.$refs[formName].resetFields();
      },
      clearRuleForm(){
        this.ProductList=[];
        this.ruleForm={
          HotelId: '',
          HotelName: '',
          ContactName: '',
          ContactPhone: '',
          SalesmanName: '',
          Remark:'',
          AllAmount:0,
          SellingPriceAmount:0,
          PaymentMode:3,
          FromChannel: !!this.ChannelList[0]?parseInt(this.ChannelList[0].Code):'',
          TravelAgency:'',
          SalesmanId:0
        }
        !!this.$refs['ruleForm']?this.$refs['ruleForm'].resetFields():'';
      },
      getDialogRoomData(data){
        let finData=[];
        let obj={};
        let getdd=(date)=>{return this.$format('yyyy-MM-dd',new Date(new Date(date).getTime() - 3600 * 1000 * 24))};
        let getend=(date)=>{return this.$format('yyyy-MM-dd',new Date(new Date(date).getTime() + 3600 * 1000 * 24))};
        _.map(data,(val)=>{
          val.startDate=this.searchData.StartDate+' 12:00:00';
          val.endDate=this.searchData.EndDate+' 12:00:00';
          finData=finData.concat(val);
        })
        return finData;
      },
			handleAdd(index,row) {
        if(row.DetailList.every(val=>{return !val.RoomList})){
          this.$message.error('请选择房间数!');
          return
        }
        this.clearRuleForm();
        this.ruleForm.HotelId=row.HotelId;
        this.ruleForm.HotelName=row.HotelName;
        let data=[];
        _.map(this.selectedRoom,val=>{
          if(val.HotelId===row.HotelId){
            data.push(val)
          }
        })
        this.dialogData=this.getDialogRoomData(data);
        this.dialogTitle='预定';
        this.OrderAction=1;
        this.$ajax.GetRoomCategoryList({hotelId:row.HotelId}).then(res=>{
          if(res.Success&&res.Data){
            this.roomNumData=[];
            _.map(res.Data,val=>{
              this.roomNumData.push({
                roomName:val.Name,
                isopen:true,
                roomId:val.Id,
                roomData:val.RoomNos
              })
            })
            _.map(this.dialogData,val=>{
              this.$ajax.getpolicylist({roomCategoryId:val.Id,hotelId:row.HotelId}).then(res=>{
                if(res.Success){
                  val.CategoryList=res.Data;
                }
              })
              let data={roomCategoryId:val.Id,rooms:val.RoomCount,policyConfigId:val.PolicyId,date:this.searchData.StartDate,days:this.getAlldate(this.searchData.StartDate,this.searchData.EndDate).length===1?1:this.getAlldate(this.searchData.StartDate,this.searchData.EndDate).length-1};
              this.$ajax.singlepolicyprice(data).then(res=>{
                if(res.Success){
                  this.ruleForm.AllAmount+=res.Data;
                  this.ruleForm.SellingPriceAmount+=res.Data;
                  val.AllAmount=res.Data;
                  val.PolicyPriceAmount=res.Data;
                  this.showAddRoom();
                }
              })
            })
          }
        })
      },
      getFromChannel1(id){
        this.ruleForm.TravelAgency='';
        if(id==7||id==8){
          _.map(this.ChannelList,val=>{
            if(val.Code==id){
              this.ChannelChildList=val.Childs
            }
          })
        }else{
          this.ChannelChildList=[];
        }
      },
      showAddRoom(){
        this.$ajax.GetUserListByOrgId({orgId:JSON.parse(sessionStorage.getItem('nowmenu')).Id}).then(res=>{
          if(res.Success){
            this.SalesmanList=res.Data;
            this.$ajax.Channels().then(res=>{
              if(res.Success){
                this.ChannelList=res.Data;
                this.roomShow=true;
              }
            })
          }
        })
      },
      getroomPrice(val){
        if(!val.PolicyId)return;
        let data={roomCategoryId:val.roomId,policyConfigId:val.PolicyId,rooms:val.RoomCount,date:this.searchData.StartDate,days:this.getAlldate(this.searchData.StartDate,this.searchData.EndDate).length===1?1:this.getAlldate(this.searchData.StartDate,this.searchData.EndDate).length-1};
        this.ruleForm.AllAmount-=val.AllAmount;
        this.ruleForm.SellingPriceAmount-=val.AllAmount;
        this.$ajax.singlepolicyprice(data).then(res=>{
          if(res.Success){
            this.ruleForm.AllAmount+=res.Data;
            this.ruleForm.SellingPriceAmount+=res.Data;
            val.AllAmount=res.Data;
            val.PolicyPriceAmount=res.Data;
          }
        },rej=>{
          val.AllAmount=0;
          val.PolicyPriceAmount=0;
        })
      },
      getMroomData(val,index){
        this.$ajax.getpolicylist({roomCategoryId:val.roomId,hotelId:val.HotelId}).then(res=>{
          if(res.Success){
            val.PolicyId='';
            val.CategoryList=res.Data;
            this.$set(this.dialogData,index,val);
          }
        })
      },
      getFromChannel1(id){
        this.ruleForm.TravelAgency='';
        if(id==7||id==8){
          _.map(this.ChannelList,val=>{
            if(val.Code==id){
              this.ChannelChildList=val.Childs
            }
          })
        }else{
          this.ChannelChildList=[];
        }
      },
      getAllAmount(){
        this.ruleForm.AllAmount=0;
        this.ruleForm.SellingPriceAmount=0;
        _.map(this.dialogData,val=>{
          this.ruleForm.AllAmount+=parseFloat(val.AllAmount);
          this.ruleForm.SellingPriceAmount+=parseFloat(val.PolicyPriceAmount);
        })
        _.map(this.ProductList,val=>{
          this.ruleForm.AllAmount+=parseFloat(val.AllAmount);
          this.ruleForm.SellingPriceAmount+=parseFloat(val.SellingPriceAmount);
        })
      },
      addPriceRoomIn(formName){
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.tableDatas.push(this.priceForm);
            this.priceShow=false;
            this.tableShow=true;
          } else {
            return false;
          }
        });
      },
      addPriceInfo(command){
        this.priceTitle=command.name;
        this.priceForm={
          Amount:'',
          Remark:'',
          CashierChannel:this.priceTitle=="收款"?4:this.priceTitle=="收押金"?1:'',
          CashierItem:command.type,
          OrderSerialid:this.orderSerialid
        }
        this.priceShow=true;
        this.$nextTick(()=>{
          this.$refs.priceFormAmount.focus();
        })
      },
      submitOrder(){
        this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
              let data={
                OrderAction: this.OrderAction,
                ...this.ruleForm,
                RoomList: [],
                ProductList: []
              }
              _.map(this.dialogData,val=>{
                data.RoomList.push({
                  "Id":this.OrderAction===0?val.HotelOrderId:0,
                  "RoomCategoryName": val.roomName,
                  "RoomCategoryPolicyId": val.PolicyId,
                  HotelId: this.ruleForm.HotelId,
                  HotelName: this.ruleForm.HotelName,
                  "RoomCategoryId": val.roomId,
                  "RoomId":val.Id,
                  "CheckInDate": val.startDate,
                  "CheckOutDate": val.endDate,
                  "Days": this.getAlldate(val.startDate,val.endDate).length-1,
                  PolicyPriceAmount:val.PolicyPriceAmount,
                  "AllAmount": val.AllAmount,
                  RoomCount:val.RoomCount
                })
              })
              _.map(this.ProductList,val=>{
                data.ProductList.push({
                  ...val
                })
              })
              this.$ajax.placeblocorder(data).then(res=>{
                if(res.Success){
                  this.$message.success('预定成功!');
                  if(!!this.tableDatas.length){
                    _.map(this.tableDatas,(val,index)=>{
                      let datas=_.cloneDeep(val);
                      datas.OrderSerialid=res.Data;
                      this.$ajax.savecashierrecord(datas).then(res=>{
                        if(res.Success&&index===this.tableDatas.length-1){
                          this.initList();
                          this.roomShow=false;
                        }
                      })
                    })
                  }else{
                    this.initList();
                    this.roomShow=false;
                  }
                }
              })
              }
            }
          )
      },
      querySearchAsync(queryString, cb) {
        if(!queryString)return;
        this.$ajax.QueryMember({nameOrMobile:queryString}).then(res=>{
          if(res.Success){
            let data=res.Data.map(item=>{return {value:item.Value,Phone:item.Key}})
            cb(data);
          }
        })
      }
    }
  }
</script>
